﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PersonalWebsite.Domain.Abstract.Configuration;
using PersonalWebsite.Domain.Entities.Post;
using PersonalWebsite.Domain.Entities.Website;

namespace PersonalWebsite.Domain.Configurations.Post;

public class WP_PostConfiguration : BaseConfiguration<WP_Post>
{
    public override void Configure(EntityTypeBuilder<WP_Post> builder)
    {
        builder.ToTable(nameof(WP_Post));

        builder.Property(c => c.Title).HasComment("名称").IsRequired().HasMaxLength(50);
        builder.Property(c => c.Category).HasComment("类型").IsRequired().HasMaxLength(20);
        builder.HasIndex(c => c.Category);

        builder.Property(c => c.Desc).HasComment("描述").HasMaxLength(200).IsRequired(false);
        builder.Property(c => c.Tags).HasComment("标签").HasMaxLength(100).IsRequired(true);
        builder.Property(c => c.Time).HasComment("发布时间").HasDefaultValue(DateTime.Now);
        builder.HasIndex(c => c.Time);

        builder.Property(c => c.IsOutlink).HasComment("是否外部连接").HasDefaultValue(true);
        builder.Property(c => c.LinkUrl).IsUnicode(false).HasMaxLength(300).HasComment("外部链接地址").IsRequired(false);

        base.Configure(builder);
    }
}